﻿using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using System.IO;

namespace FunnyArts.PrettyClient.LocalDb.Entities
{
    public partial class LocalContext : DbContext
    {
        public LocalContext()
        {
        }

        public LocalContext(DbContextOptions<LocalContext> options)
            : base(options)
        {
        }

        public virtual DbSet<CacheMgrEntity> CacheMgrEntities { get; set; } = null!;

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlite($"Data Source={Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Db\\local.db")}");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<CacheMgrEntity>(entity =>
            {
                entity.HasKey(k=>k.Id);

                entity.ToTable("CacheMgr");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Key).HasColumnName("key");

                entity.Property(e => e.Value).HasColumnName("value");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
